<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
    <head>
        <th:block th:include="common/include :: header('菜单编辑')" />
    </head>
    <body class="white-bg">
        <div class="wrapper wrapper-content animated fadeInRight ibox-content">
            <form class="form-horizontal m" id="form-menu-add">
                <input id="treeId" name="id" type="hidden" th:value="${menu.id}" />
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜单类型：</label>
                    <div class="col-sm-8">
                        <label class="radio-box"> <input type="radio" th:field="*{menu.type}" name="type" value="0" /> 目录 </label>
                        <label class="radio-box"> <input type="radio" th:field="*{menu.type}" name="type" value="1" /> 菜单 </label>
                        <label class="radio-box"> <input type="radio" th:field="*{menu.type}" name="type" value="2" /> 按钮 </label>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜单名称：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="name" id="menuName" th:value="${menu.name}" required>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">请求地址：</label>
                    <div class="col-sm-8">
                        <input id="url" name="url" class="form-control" type="text" th:value="${menu.url}">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">权限标识：</label>
                    <div class="col-sm-8">
                        <input id="perms" name="permission" class="form-control" type="text" th:value="${menu.permission}">
                        <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 控制器中定义的权限标识，如：@RequiresPermissions("")</span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">显示排序：</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="sort" required th:value="${menu.sort}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">图标：</label>
                    <div class="col-sm-8">
                        <input id="classStyle" name="classStyle" class="form-control" type="text" placeholder="选择图标" th:value="${menu.classStyle}">
                        <div class="ms-parent" style="width: 100%;">
                            <div class="icon-drop animated flipInX" style="display: none;max-height:200px;overflow-y:auto">
                                <div data-th-include="service/menu/icon"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">菜单状态：</label>
                    <div class="col-sm-8">
                        <label class="radio-box"> <input type="radio" name="isshow" value="1" th:field="*{menu.isshow}"/> 显示 </label>
                        <label class="radio-box"> <input type="radio" name="isshow" value="0" th:field="*{menu.isshow}"/> 隐藏 </label>
                    </div>
                </div>
            </form>
        </div>
        <th:block th:include="common/include :: footer" />
        <script>
            var prefix = ctx + "menuAction";
            function submitHandler(callback) {
                debugger;
                //TODO 添加业务判断
                $.form.submit( prefix+'/menuEdit','post',$('#form-menu-add'),callback);

            }
            // function callback(){
            //     $.modal.close();
            // }
            $(function() {
                $("input[name='classStyle']").focus(function() {
                    $(".icon-drop").show();
                });
                $("#form-menu-add").click(function(event) {
                    var obj = event.srcElement || event.target;
                    if (!$(obj).is("input[name='classStyle']")) {
                        $(".icon-drop").hide();
                    }
                });
                $(".icon-drop").find(".ico-list i").on("click", function() {
                    $('#classStyle').val($(this).attr('class'));
                });
                $('input').on('ifChecked', function(event){
                    var menuType = $(event.target).val();
                    if (menuType == "M") {
                        $("#url").parents(".form-group").hide();
                        $("#perms").parents(".form-group").hide();
                        $("#classStyle").parents(".form-group").show();
                        $("#target").parents(".form-group").hide();
                        $("input[name='visible']").parents(".form-group").show();
                    } else if (menuType == "C") {
                        $("#url").parents(".form-group").show();
                        $("#perms").parents(".form-group").show();
                        $("#classStyle").parents(".form-group").show();
                        $("#target").parents(".form-group").show();
                        $("input[name='visible']").parents(".form-group").show();
                    } else if (menuType == "F") {
                        $("#url").parents(".form-group").hide();
                        $("#perms").parents(".form-group").show();
                        $("#classStyle").parents(".form-group").hide();
                        $("#target").parents(".form-group").hide();
                        $("input[name='visible']").parents(".form-group").hide();
                    }
                });
            });

            /*菜单管理-新增-选择菜单树*/
            function selectMenuTree() {
                var treeId = $("#treeId").val();
                var menuId = treeId > 0 ? treeId : 1;
                var url = prefix + "/selectMenuTree/" + menuId;
                var options = {
                    title: '菜单选择',
                    width: "380",
                    url: url,
                    callBack: doSubmit
                };
                $.modal.openOptions(options);
            }

            function doSubmit(index, layero){
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        </script>
</body>
</html>